package com.chao.base.equals;

import com.chao.base.obj.Person;
import com.chao.base.obj.PersonOverride;

import java.util.HashMap;

/**
 * @author : Rookie
 * @description :
 * @date : 2022/10/29
 */
public class EqualsTest {

    public static void main(String[] args) {
        //基本类型的比较
        int a = 10;
        int b = 10;
        System.out.println(a == b);

        //引用类型比较 String 使用常量池初始化
        String s1 = "hello";
        String s2 = "hello";
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
        System.out.println(s1.equals("hello"));

        //创建引用对象
        String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));
        System.out.println(str1.equals("hello"));

        //未重写equals方法的对象比较
        Person p1 = new Person();
        Person p2 = new Person();
        System.out.println(p1);
        System.out.println(p2);
        System.out.println(p1 == p2);
        System.out.println(p1.equals(p2));

        //重写equals方法
        PersonOverride p3 = new PersonOverride();
        PersonOverride p4 = new PersonOverride();
        System.out.println(p3);
        System.out.println(p4);
        System.out.println(p3 == p4);
        System.out.println(p3.equals(p4));
    }
}
